package saas.dev.cloud.controller;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import saas.dev.cloud.controller.param.LoginParam;
import saas.dev.cloud.util.JwtUtil;
import saas.dev.cloud.util.RedisUtils;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @ClassName : AuthController
 * @Author : y1
 * @Date: 2022/5/18 14:24
 * @Description :
 */
@RestController
@RequestMapping(value = "auth", method = RequestMethod.POST)
public class AuthController {
    @Autowired
    private RedisUtils redisUtils;

    @RequestMapping("login")
    public String login(@RequestBody LoginParam param) {
        List<String> roles = Stream.of("/user/list", "/store/list","/test").collect(Collectors.toList());
        String token = JwtUtil.generate(new JSONObject(param));
        redisUtils.set(token, JSON.toJSONString(roles));
        return token;
    }
}
